#include "common.h"
#include "lmodel.h"

layout(location = TEXCOORD0) in vec4 tc;

layout(location = COLOR0) out vec4 oColor;

//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
// Note: this is a half-sphere
uniform half3		direction;

void main ()
{
	float4 _P		= tex2Dproj 	(s_position, 	tc); 
	half4 _N		= tex2Dproj 	(s_normal,   	tc); 

	half3	L2P 	= _P.xyz - Ldynamic_pos.xyz;			// light2point
	half3 	L2P_N 	= normalize	( L2P );					// light2point
	half	rsqr	= dot		( L2P, L2P );				// distance 2 light (squared)
	half  	att 	= saturate	( 1 - rsqr*Ldynamic_pos.w );// q-linear attenuate
	half  	light	= saturate	( dot( -L2P_N, _N.xyz ) );
	half	hemi 	= saturate	( dot( L2P_N, direction ) );

	// Final color
	oColor			= blendp( half4( Ldynamic_color.xyz * att * light * hemi, 0 ), tc );
}